import order from 'src/api/order';
import meEndpoint from 'src/api/meEndpoint';
import { dispatch } from 'src/redux/store';
import { finishWaiting, startWaiting } from 'src/redux/uiSlice';
import { setAccountInfo } from 'src/redux/authSlice';
import { init } from 'src/service/appService';

type PostAuthRequest = any


export const getAdGoods = async (data: PostAuthRequest) => {
  try {
    dispatch(startWaiting());
    const res = await order.getAdGoods(data);
    return data.data = res.data
  } finally {
    dispatch(finishWaiting());
  }
};
export const addMyAdGoods = async (data: PostAuthRequest) => {
  try {
    dispatch(startWaiting());
    const res = await order.addMyAdGoods(data);
    if (res.data.success) {
      init()
    }
    return data.data = res.data
  } finally {
    dispatch(finishWaiting());
  }
};

export const getMyAdGoods = async (data: PostAuthRequest) => {
  try {
    dispatch(startWaiting());
    const res = await order.getMyAdGoods(data);
    return data.data = res.data
  } finally {
    dispatch(finishWaiting());
  }
};
export const getMyDetails = async (data: PostAuthRequest) => {
  try {
    dispatch(startWaiting());
    const res = await order.getMyDetails(data);
    return data.data = res.data
  } finally {
    dispatch(finishWaiting());
  }
};
export const getMyOrder = async (data: PostAuthRequest) => {
  try {
    dispatch(startWaiting());
    const res = await order.getMyOrder(data);
    return data.data = res.data
  } finally {
    dispatch(finishWaiting());
  }
};
export const delMyAdGoods = async (data: PostAuthRequest) => {
  try {
    dispatch(startWaiting());
    const res = await order.delMyAdGoods(data);
    return data.data = res.data
  } finally {
    dispatch(finishWaiting());
  }
};
export const updateOrder = async (data: PostAuthRequest) => {
  try {
    dispatch(startWaiting());
    const res = await order.updateOrder(data);
    return data.data = res.data
  } finally {
    dispatch(finishWaiting());
  }
};
